/*
 * @Author: deng da chao
 * @Date: 2022-10-08 17:24:54
 * @LastEditTime: 2022-10-18 15:19:18
 * @Description: 
 */
import React, { Component } from 'react'
import store from '../../redux/store.js'


export default class index extends Component {
  constructor(props) {
    super(props);
    this.state = { value: '' };

    this.handleChange = this.handleChange.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);
  }
  goPahe = () => {
    this.props.history.push('/scenario')
  }

  handleChange(event) {
    this.setState({ value: event.target.value });
  }

  handleSubmit(event) {
    const { value } = this.state;
    store.dispatch({
      type: 'setUpUserNmae',
      data: value,
    })
    this.goPahe();
    event.preventDefault();
  }
  render() {
    return (
      <form onSubmit={this.handleSubmit}>
        <label>
          名字:
          <input type="text" value={this.state.value} onChange={this.handleChange} placeholder="起一个名字" />
        </label>
        <input type="submit" value="领取树苗" />
      </form>
    )
  }
}
